package lee.vioson.ebook.viewmodels

import kotlinx.coroutines.flow.StateFlow
import lee.vioson.composecommon.base.mvi.BaseViewModel
import lee.vioson.composecommon.base.mvi.Reducer
import lee.vioson.composecommon.base.mvi.UiEvent
import lee.vioson.composecommon.base.mvi.UiState
import lee.vioson.ebook.data.AppContainer
import lee.vioson.ebook.data.pagedata.pageDataSource

/**
 *Author:viosonlee
 *Date:2023/6/16
 *DESCRIPTION:
 */
class FavoritesViewModel(private val appContainer: AppContainer) :
    BaseViewModel<FavoritesViewModel.State, FavoritesViewModel.Event>() {

    private val reducer = SubReducer(State())

    override val state: StateFlow<State>
        get() = reducer.state

    override fun sendEvent(event: Event) {
        reducer.sendEvent(event)
    }

    val myFavorites = pageDataSource { appContainer.homeRepository.myFavorites(it) }

    val mostFavoritesPageData = pageDataSource { appContainer.homeRepository.mostFavorites(it) }

    private class SubReducer(initialState: State) :
        Reducer<State, Event>(initialState) {
        override fun reduce(oldState: State, event: Event) {

        }
    }


    sealed class Event : UiEvent

    data class State(
        val isVip: Boolean = false
    ) : UiState
}

